package practise.mulitThreads.EventSystem;

import practise.mulitThreads.EventSystem.impl.ClientImpl;
import practise.mulitThreads.EventSystem.impl.ContainerImpl;
import practise.mulitThreads.EventSystem.impl.ServerImpl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by angela on 7/27/2014.
 */
public class SystemBooter {
    public static void main(String[] args) {
        ExecutorService serverExecutor = Executors.newCachedThreadPool();
        ExecutorService clientExecutor = Executors.newCachedThreadPool();
        ContainerImpl container = new ContainerImpl(10);
        for(int i=0; i<5;i++){
            container.addConsumer(new ClientImpl());
            container.addProducer(new ServerImpl());
        }
        for(ContainerOperator client : container.getClientList()){
            clientExecutor.execute(client);
        }

        for(ContainerOperator server: container.getServers()){
            serverExecutor.execute(server);
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        serverExecutor.shutdownNow();
        clientExecutor.shutdownNow();
    }
}
